import systemService  from "../../service/system/systemService";
const koaRouter = require('koa-router');
const router = koaRouter();

/**
 * -----------------------------------用户管理------------------------------------------
 **/

// 用户列表
router.get('/getUserList',async(ctx)=>{
	let result:any=await new systemService().getUserList(ctx.request.query);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})
// 保存或编辑用户
router.post('/saveUser',async(ctx)=>{
	let result:any=await new systemService().saveUser(ctx.request.body);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})
// 删除or禁用or启用
router.post('/delUser',async(ctx)=>{
	let result:any=await new systemService().delUser(ctx.request.body);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})
// 批量删除用户
router.post('/delMoreUser',async(ctx)=>{
	let result:any=await new systemService().delMoreUser(ctx.request.body);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})


/**
 * ----------------------------------------角色管理----------------------------------------------
 **/

//角色列表
router.get('/getRoleList',async(ctx)=>{
    let result:any=await new systemService().getRoleList(ctx.request.query);
    if(result){
        ctx.body ={success:true,datas:result};
    }else{
        ctx.body ={success:false,msg:"未知错误"};
    }
})
//角色列表不分页
router.get('/getRoleListNopage',async(ctx)=>{
    let result:any=await new systemService().getRoleListNopage();
    if(result){
        ctx.body ={success:true,datas:result};
    }else{
        ctx.body ={success:false,msg:"未知错误"};
    }
})
//保存或编辑角色
router.post('/saveRole',async(ctx)=>{
    let result:any=await new systemService().saveRole(ctx.request.body);
    if(result){
        ctx.body ={success:true,datas:result};
    }else{
        ctx.body ={success:false,msg:"未知错误"};
    }
})
//删除角色
router.post('/delRole',async(ctx)=>{
    let result:any=await new systemService().delRole(ctx.request.body.id);
    if(result){
        ctx.body ={success:true,datas:result};
    }else{
        ctx.body ={success:false,msg:"未知错误"};
    }
})
//查询某个角色权限
router.get('/getMenuRole',async(ctx)=>{
  let result:any=await new systemService().getMenuRole(ctx.request.query);
  if(result){
      ctx.body ={success:true,datas:result};
  }else{
      ctx.body ={success:false,msg:"未知错误"};
  }
})


/**
 * -------------------------------------------菜单管理--------------------------------------------
 **/

//菜单列表
router.get('/getMenuList',async(ctx)=>{
  let result:any=await new systemService().getMenuList();
  if(result){
      ctx.body ={success:true,datas:result};
  }else{
      ctx.body ={success:false,msg:"未知错误"};
  }
})
// 添加菜单
router.post('/saveMenu',async(ctx)=>{
	let result:any=await new systemService().saveMenu(ctx.request.body);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})
// 删除菜单
router.post('/delMenu',async(ctx)=>{
	let result:any=await new systemService().delMenu(ctx.request.body.id);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})



/**
 * -------------------------------------------部门管理--------------------------------------------
 **/

// 部门列表
router.get('/getDepartmentList',async(ctx)=>{
	let result:any=await new systemService().getDepartmentList(ctx.request.query);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})

// 保存或编辑部门
router.post('/saveDepartment',async(ctx)=>{
	let result:any=await new systemService().saveDepartment(ctx.request.body);
	if(result){
		ctx.body ={success:true,datas:result};
	}else{
		ctx.body ={success:false,msg:"未知错误"};
	}
})
//删除部门
router.post('/delDepartment',async(ctx)=>{
    let result:any=await new systemService().delDepartment(ctx.request.body.id);
    if(result){
        ctx.body ={success:true,datas:result};
    }else{
        ctx.body ={success:false,msg:"未知错误"};
    }
})


module.exports = router;